package com.xuetang9.wordreview.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuetang9.wordreview.dao.WordDao;
import com.xuetang9.wordreview.domain.WordDomain;
import com.xuetang9.wordreview.request.WordCreatOrUpdateRequest;
import com.xuetang9.wordreview.request.WordPageRequest;
import com.xuetang9.wordreview.service.WordService;
import org.springframework.stereotype.Service;

/**
 * <p>Description:  </p>
 * <p>CreateTime:   2020/7/4 </p>
 *
 * @author fujian
 */
@Service("wordService")
public class WordServiceImpl extends ServiceImpl<WordDao, WordDomain> implements WordService {

    @Override
    public void del(Integer id) {
        baseMapper.deleteById(id);
    }

    @Override
    public void creatOrUpdateWord(WordCreatOrUpdateRequest request) {
        WordDomain wordDomain = new WordDomain();
        wordDomain.setEnglish(request.getEnglish());
        wordDomain.setChinese(request.getChinese());
        if (null != request.getId()) {
            wordDomain.setId(request.getId());
            baseMapper.updateById(wordDomain);
        } else {
            baseMapper.insert(wordDomain);
        }
    }

    @Override
    public IPage<WordDomain> page(WordPageRequest request) {
        Page page = request.pager();
        return baseMapper.page(page,request);
    }
}
